
package com.letoo.sso.api.springfox;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * springfox配置。扫描系统中全部controller。
 * 
 * @author dengjie
 *
 */
@Configuration
@EnableSwagger2
public class Swagger2 {
  @Bean
  public Docket adminApi() {
    return new Docket(DocumentationType.SWAGGER_2).groupName("Admin API").forCodeGeneration(true).pathMapping("/")
        .select().paths(paths()).build().apiInfo(apiInfo()).useDefaultResponseMessages(false);
  }

  private Predicate<String> paths() {
    return Predicates.and(PathSelectors.regex("/.*"), Predicates.not(PathSelectors.regex("/error")));
  }

  private ApiInfo apiInfo() {
    Contact contact = new Contact("后端开发团队", "https://www.letoo.com/", "jie.deng@letoo.com");
    return new ApiInfoBuilder().title("SSO系统API").description("SSO系统所有API包含spring-boot-actuator接口").contact(contact)
        .build();
  }
}
